/*
 * @Project Name: spring-boot
 * @File Name: UserService
 * @Package Name: com.hhly.spring.boot.cache
 * @Date: 2017/12/13 17:52
 * @Creator: linshixing-1199
 * @line------------------------------
 * @修改人:
 * @修改时间:
 * @修改内容:
 */

package com.sm.shoplook.service.service.impl;

import java.util.Date;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sm.shoplook.constant.ResultMessage;
import com.sm.shoplook.dao.mapper.service.SlServiceMapper;
import com.sm.shoplook.domain.service.SlService;
import com.sm.shoplook.service.service.SlSerService;
import com.sm.shoplook.vo.base.ApiException;
import com.sm.shoplook.vo.base.ApiResult;
import com.sm.shoplook.vo.service.req.SlServicePageSearchReqVo;

/**
 * @author chenpy-1072
 * @desc 服务
 * @date 2017/12/13 17:52
 * @see
 */
@Service
public class SLSerServiceImpl implements SlSerService {

	private static final Logger LOGGER = LoggerFactory.getLogger(SLSerServiceImpl.class);
	@Autowired
	private SlServiceMapper slServiceMapper;

	@Override
	public ApiResult<PageInfo<SlService>> selectSlServicePage(SlServicePageSearchReqVo slServicePageSearchReqVo) {
		PageHelper.startPage(slServicePageSearchReqVo.getOffset(), slServicePageSearchReqVo.getPageSize());
		List<SlService> slServices = slServiceMapper.selectSlServicePage(slServicePageSearchReqVo);
		return new ApiResult<>(ResultMessage.RESULT_SUCCESS_1, new PageInfo<>(slServices));
	}

	@Override
	public ApiResult deleteSlService(String[] idList) throws ApiException {
		int i = slServiceMapper.deleteSlService(idList);
		if (i < 1) {
			throw new ApiException();
		}
		return new ApiResult(ResultMessage.RESULT_SUCCESS_1);
	}

	@Override
	public ApiResult saveSlService(SlService slService) throws ApiException {
		int i;
		if (slService.getId() == null) {
			slService.setCreateTime(new Date());
			i = slServiceMapper.insertSelective(slService);
		} else {
			i = slServiceMapper.updateByPrimaryKeySelective(slService);
		}
		if (i < 1) {
			throw new ApiException();
		}
		return new ApiResult(ResultMessage.RESULT_SUCCESS_1);
	}

	@Override
	public ApiResult<SlService> selectSlServiceById(Integer id) {
		return new ApiResult<>(ResultMessage.RESULT_SUCCESS_1, slServiceMapper.selectByPrimaryKey(id));
	}
}
